const Koa = require('koa')
const config = require('./config')
const secret = config.jwt_config.secretKey
const app = new Koa()
const bodyParser = require('koa-bodyparser')
const body = require('koa-body')
const cors = require('koa2-cors')
// const jwtKoa = require('koa-jwt')

app.use(cors());
const jwt = require('jsonwebtoken')


// const util = require('util')
// const verify = util.promisify(jwt.verify)


console.log('secret:', secret)
// 数组中的路径不需要通过jwt验证
// app.use(jwtKoa({ secret }).unless({
//   path: [/^\/api\/user\/.*?/]
// }))



// app.use((ctx) => {
//   ctx.body = 'Hello koa'
// })


// koa解析post请求参数
app.use(bodyParser())

const router = require('./routes')
app.use(router.routes())


router.get('/menu/list', (ctx) => {
  console.log('开始登录', ctx.request.body)
  const data = ['abc', 'bcd', 'cde']
  ctx.body = {
        code: 200,
        data
      }
})

app.listen(config.port, () => {
  console.log(`➜  Local:   http://localhost:${config.port}`)
  console.log(`➜  Network: http://192.168.1.3:${config.port}`)
})
